package com.team06.dao;

import com.team06.pojo.Apue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class ApueDao {
    private static final Logger LOGGER = LoggerFactory.getLogger(ApueDao.class.getName());
    private final JdbcTemplate jdbcTemplate;

    public ApueDao(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    public void insertMessage(Apue entity) {
        String sql = "INSERT INTO MSG_BASE_APUE (" +
                "META_SNDR, META_RCVR, META_SEQN, META_DDTM, META_TYPE, META_STYP, " +
                "APOT_CODE, APOT_FRCD, APOT_APAT, APOT_CNNM, APOT_ENNM, " +
                "APOT_AISO, APOT_APSN) " +
                "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

        try {
            jdbcTemplate.update(sql,
                    entity.getMetaSnDR(),
                    entity.getMetaRCVR(),
                    entity.getMetaSEQN(),
                    entity.getMetaDDTM(),
                    entity.getMetaTYPE(),
                    entity.getMetaSTYP(),
                    entity.getApotCode(),
                    entity.getApotFrcd(),
                    entity.getApotApat(),
                    entity.getApotCnnm(),
                    entity.getApotEnnm(),
                    entity.getApotAiso(),
                    entity.getApotApsn()
            );
            LOGGER.info("数据插入成功（通过 Spring JDBC）");
        } catch (Exception e) {
            LOGGER.error("Failed to insert message into database", e);
            throw new RuntimeException("Failed to insert message into database", e);
        }
    }
}